package com.appclub.kitsilano.info;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.view.MenuItem;
import com.appclub.kitsilano.MainActivity;
import com.appclub.kitsilano.R;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

public class Info extends SherlockActivity implements ActionBar.TabListener {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		ActionBar.Tab tab1 = getSupportActionBar().newTab();
		ActionBar.Tab tab2 = getSupportActionBar().newTab();
		tab1.setText("app version");
		tab2.setText("school info");
		tab1.setTabListener(this);
		tab2.setTabListener(this);
		getSupportActionBar().addTab(tab1);
		getSupportActionBar().addTab(tab2);
		tab1.setTabListener(tabListener);
		tab2.setTabListener(tabListener2);
		setContentView(R.layout.info_app_version_tab);
		appversion();
	}

	ActionBar.TabListener tabListener = new ActionBar.TabListener() {
		public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
			setContentView(R.layout.info_app_version_tab);
			appversion();
		}

		public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
		}

		public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
		}
	};
	ActionBar.TabListener tabListener2 = new ActionBar.TabListener() {
		public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
			setContentView(R.layout.info_school_info_tab);
		}

		public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
		}

		public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
		}
	};

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			Intent intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			overridePendingTransition(R.anim.right_in, R.anim.right_out);
			return true;
		default:
			return super.onOptionsItemSelected(item);
		}
	}

	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}

	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}

	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub

	}

	protected void appversion() {
		Button contact_us = (Button) findViewById(R.id.contact);
		contact_us.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(Info.this, ContactUs.class);
				startActivity(intent);
				overridePendingTransition(R.anim.bottom_in, R.anim.bottom_out);
			}
		});

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			Intent intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			overridePendingTransition(R.anim.right_in, R.anim.right_out);
			this.finish();
		}
		return true;
	}
}